package com.wswy.wzcx.model.car

import android.os.Parcel
import android.os.Parcelable
import android.text.TextUtils
import com.google.gson.annotations.SerializedName

data class CarTypeInfo(@SerializedName("id") val id: String? = null,

                       @SerializedName("letter") val letter: String? = null,

                       @SerializedName("name") val name: String? = null,

                       @SerializedName("logo") val logo: String? = null,

                       @SerializedName("facName") val facName: String? = null,


                       @SerializedName("year") val year: String? = null,

                       @SerializedName("fullName") val fullName: String? = null

) :Parcelable{


    @Transient var headerId :Long = 0

//    @delegate:Transient
//    val headerId by lazy {
//        var id:Long = 0
//        if (!TextUtils.isEmpty(letter)){
//            id = letter?.get(0)?.toLong()?:0
//        }
//
//        if (id == 0L && !TextUtils.isEmpty(facName)){
//            id = facName?.hashCode()?.toLong()?:0L
//        }
//          id
//    }

    @delegate:Transient
    val headerTitle by lazy {
        if (!TextUtils.isEmpty(letter)){
            letter
        }else if (!TextUtils.isEmpty(facName)){
            facName
        }else{
            year
        }
    }

    constructor(parcel: Parcel) : this(
            parcel.readString(),
            parcel.readString(),
            parcel.readString(),
            parcel.readString(),
            parcel.readString(),
            parcel.readString(),
            parcel.readString()) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(id)
        parcel.writeString(letter)
        parcel.writeString(name)
        parcel.writeString(logo)
        parcel.writeString(facName)
        parcel.writeString(year)
        parcel.writeString(fullName)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<CarTypeInfo> {
        override fun createFromParcel(parcel: Parcel): CarTypeInfo {
            return CarTypeInfo(parcel)
        }

        override fun newArray(size: Int): Array<CarTypeInfo?> {
            return arrayOfNulls(size)
        }
    }


}